import {
  ApiRemark,
  Controller,
  Get,
  Meta,
  PathVariable,
  Render,
  Request,
  RequestParam,
  Response,
} from 'j-spring-web';
import { UserService } from '@service/userService';
import { Autowired } from 'j-spring';

@Controller('/')
export class IndexApi {
  @Autowired()
  userService: UserService;

  @Get('/')
  @Render('testPage')
  @ApiRemark('运行提示')
  async index() {
    return { data: 'hello world!' };
  }

  @Get()
  @ApiRemark('测试jpa')
  async doTestJpa() {
    return await this.userService.doTestJpa();
  }

  @Get('/testParaFIlter/{b}')
  @ApiRemark('测试参数拦截')
  async testParaFIlter(
    @RequestParam('a') a: string,
    @PathVariable('b') b: string,
    @Meta() req: Request, //原始express req,res对象
    @Meta() res: Response
  ) {
    console.log({ a, b, req, res });
    return 'pass';
  }

  //测试页面渲染 可以在配置里面更改渲染引擎  默认ejs  输入 http://localhost:3000/html
  @Render('testPage')
  @ApiRemark('渲染页面')
  async html() {
    return { msg: 'hello world!' };
  }
}
